package cs342.project1.mathNotebook.gui;

import java.awt.BorderLayout;
import java.awt.Container;
import java.util.Calendar;
import java.util.GregorianCalendar;

import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;

public class PermissionsTable extends AbstractTableModel {
	
	private String[] columnNames = {"Username", "Read-Write", "Read Only"};
	private Object[][] data;
	
	public PermissionsTable(Object[][] data){
		this.data = data;
	}
	
	public int getColumnCount() {
        return columnNames.length;
    }

    public int getRowCount() {
    	return data.length;
    }

    public String getColumnName(int col) {
        return columnNames[col];
    }

    public Object getValueAt(int row, int col) {
        return data[row][col];
    }

    public Class getColumnClass(int column) {
    	Object value=this.getValueAt(0,column);  
    	return (value==null?Object.class:value.getClass());  
    	//return getValueAt(0, column).getClass();
    }

    public Object[][] getData(){
    	return data;
    }
    
    /*
     * Don't need to implement this method unless your table's
     * editable.
     */
    public boolean isCellEditable(int row, int col) {
        //Note that the data/cell address is constant,
        //no matter where the cell appears onscreen.
        if (col < 1) {
            return false;
        } else {
            return true;
        }
    }

    /*
     * Don't need to implement this method unless your table's
     * data can change.
     */
    public void setValueAt(Object value, int row, int col) {
        //data[row][col] = value;
        
        if(col == 1){
        	boolean bool_one = (Boolean)(data[row][col]);
        	boolean bool_two = (Boolean)(data[row][col+1]);
        	
        	if(bool_one){
        		data[row][col] = false;
        	}
        	else{
        		data[row][col] = true;
        		data[row][col+1] = false;
        	}
        	
        	fireTableCellUpdated(row, col);
            fireTableCellUpdated(row, col+1);
        }
        else if(col == 2){
        	boolean bool_one = (Boolean)(data[row][col-1]);
        	boolean bool_two = (Boolean)(data[row][col]);
        	data[row][col-1] = !bool_one;
        	data[row][col] = !bool_two;
        	
        	if(bool_two){
        		data[row][col] = false;
        		data[row][col-1] = false;
        	}
        	else{
        		data[row][col] = true;
        		data[row][col-1] = false;
        	}
        	
        	fireTableCellUpdated(row, col-1);
            fireTableCellUpdated(row, col);
        }       
        
    }
	
}

 